﻿using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Collections.Generic;
using zdzh.zdmgr.COL;
using zdzh.zdmgr.SFL;

namespace zdzh.zdmgr.DAL.OleDb
{
    /// <summary>
    /// 对象名称：回迁户OleDb数据访问子类（数据访问层）
    /// 对象说明：提供“回迁户类（业务逻辑层）”针对OleDb的“增删改查”等各种数据访问方法，继承通用数据访问父类。
    /// 调用说明：通常不需要直接实例化本类，而使用“回迁户类（业务逻辑层）”中的DataAccess属性来调用本类所实现的方法。
    /// 作者姓名：飞翔熊
    /// 编写日期：2012-12-3 13:23:04
    /// </summary>
    public class WuyefeiDAL : DAL.Common.WuyefeiDAL
    {
        #region EasyCode所生成的默认代码
        //﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉
        //  此区域的代码为EasyCode所自动生成，实现了父类中定义的抽象方法。请不要直接修改该区域中的任何代码，   
        //  或在该区域中添加任何自定义代码，当该类发生变更时，您可以随时使用EasyCode重新生成覆盖其中的代码。  
        //﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍


        /// <summary>
        /// 将回迁户（Huiqianhu）数据，采用INSERT操作插入到数据库中，并返回受影响的行数。
        /// </summary>
        /// <param name="huiqianhu">回迁户（Huiqianhu）实例对象</param>
        public override int Insert(Wuyefei wuyefei)
        {
            int index = SFL.OleDbHelper.GetMaxIndex("wuyefei")+1;
            string sqlText = "INSERT INTO [wuyefei]"
                           + "([index],[fangyuanindex],[date],[xingming],[wuyefei],[qunuanfei],[gongshuifei],[diantifei],[zongji],[startdate],[enddate],[sellerid],[beizhu]) "
                           + "VALUES "
                           + "(@index,@fangyuanindex,@date,@xingming,@wuyefei,@qunuanfei,@gongshuifei,@diantifei,@zongji,@startdate,@enddate,@sellerid,@beizhu)";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@index"         , OleDbType.Integer , 4){ Value = index },
				new OleDbParameter("@fangyuanindex" , OleDbType.Integer,4)  {Value=wuyefei.fangyuanindex},
				new OleDbParameter("@date"          , OleDbType.Date)       {Value=wuyefei.date},
				new OleDbParameter("@xingming"      , OleDbType.VarChar,50) {Value=wuyefei.xingming},
				new OleDbParameter("@wuyefei"       , OleDbType.Decimal)    {Value=wuyefei.wuyefei},
				new OleDbParameter("@qunuanfei"     , OleDbType.Decimal)    {Value=wuyefei.qunuanfei},
				new OleDbParameter("@gongshuifei"   , OleDbType.Decimal)    {Value=wuyefei.gongshuifei},
				new OleDbParameter("@diantifei"     , OleDbType.Decimal)    {Value=wuyefei.diantifei},
				new OleDbParameter("@zongji"        , OleDbType.Decimal)    {Value=wuyefei.zongji},
                new OleDbParameter("@startdate"     ,OleDbType.Date)        {Value=wuyefei.startdate},
				new OleDbParameter("@enddate"       , OleDbType.Date)       {Value=wuyefei.enddate},
				new OleDbParameter("@sellerid"      , OleDbType.Integer,4)  {Value=wuyefei.sellerid},
				new OleDbParameter("@beizhu"        , OleDbType.VarChar,50) {Value=wuyefei.beizhu}
            };
            SFL.OleDbHelper.ExecuteNonQuery(sqlText, parameters);
            return index;
        }


        /// <summary>
        /// 将回迁户（Huiqianhu）数据，根据主键“协议号（Xieyihao）”采用UPDATE操作更新到数据库中，并返回受影响的行数。
        /// </summary>
        /// <param name="huiqianhu">回迁户（Huiqianhu）实例对象</param>
        public override int Update(Wuyefei wuyefei)
        {
            string sqlText = "UPDATE [wuyefei] SET "
                             + "[fangyuanindex]=@fangyuanindex,[date]=@date,[xingming]=@xingming,[wuyefei]=@wuyefei,[qunuanfei]=@qunuanfei,[gongshuifei]=@gongshuifei,[diantifei]=@diantifei,[zongji]=@zongji,[startdate]=@startdate,[enddate]=@enddate,[sellerid]=@sellerid,[beizhu]=@beizhu "
                             + "WHERE [index]=@index";
            OleDbParameter[] parameters = 
            {
				new OleDbParameter("@fangyuanindex", OleDbType.Integer,4){Value=wuyefei.fangyuanindex},
				new OleDbParameter("@date", OleDbType.Date){Value=wuyefei.date},
				new OleDbParameter("@xingming", OleDbType.VarChar,50){Value=wuyefei.xingming},
				new OleDbParameter("@wuyefei", OleDbType.Decimal){Value=wuyefei.wuyefei},
				new OleDbParameter("@qunuanfei", OleDbType.Decimal){Value=wuyefei.qunuanfei},
				new OleDbParameter("@gongshuifei", OleDbType.Decimal){Value=wuyefei.gongshuifei},
				new OleDbParameter("@diantifei", OleDbType.Decimal){Value=wuyefei.diantifei},
				new OleDbParameter("@zongji"        , OleDbType.Decimal)    {Value=wuyefei.zongji},
				new OleDbParameter("@start", OleDbType.Date){Value=wuyefei.startdate},
				new OleDbParameter("@enddate", OleDbType.Date){Value=wuyefei.enddate},
				new OleDbParameter("@sellerid", OleDbType.Integer,4){Value=wuyefei.sellerid},
				new OleDbParameter("@beizhu", OleDbType.VarChar,50){Value=wuyefei.beizhu},
                new OleDbParameter("@index"     , OleDbType.Integer , 4){ Value = wuyefei.index }
            };
            return SFL.OleDbHelper.ExecuteNonQuery(sqlText, parameters);
        }

        public override int Delete(int index)
        {
            string sqlText = "DELETE FROM [wuyefei] "
                           + "WHERE [index]=@index";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@index" , OleDbType.Integer , 4){ Value = index }
            };
            return SFL.OleDbHelper.ExecuteNonQuery(sqlText, parameters);
        }

        public override Wuyefei GetDataByIndex(int index)
        {
            Wuyefei wuyefei = null;
            string sqlText = "SELECT * "
                           + "FROM [wuyefei] "
                           + "WHERE [index]=@index";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@index" , OleDbType.Integer , 4){ Value = index }
            };

            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, parameters);
            if (oleDbDataReader.Read())
            {
                wuyefei = new Wuyefei();
                ReadWuyefeiAllData(oleDbDataReader, wuyefei);
            }
            oleDbDataReader.Close();
            return wuyefei;
        }


        /// <summary>
        /// 从数据库中读取并返回所有回迁户（Huiqianhu）List列表。
        /// </summary>
        public override List<Wuyefei> GetAllList()
        {
            string sqlText = "SELECT * "
                           + "FROM [wuyefei]";
            List<Wuyefei> list = new List<Wuyefei>();
            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, null);
            while (oleDbDataReader.Read())
            {
                Wuyefei wuyefei = new Wuyefei();
                ReadWuyefeiAllData(oleDbDataReader, wuyefei);
                list.Add(wuyefei);
            }
            oleDbDataReader.Close();
            return list;
        }


        /// <summary>
        /// 根据每页记录数及所要获取的页数，从数据库中读取并返回经过分页后的回迁户（Huiqianhu）的列表及分页信息。
        /// 该方法所获取的回迁户（Huiqianhu）列表仅用于在数据控件中显示，该方法只为对象中需要显示的属性进行赋值。
        /// </summary>
        public override PageData GetPageList(int pageSize, int curPage)
        {
            string sqlText = "SELECT * "
                           + "FROM [wuyefei]";
            List<Wuyefei> list = new List<Wuyefei>();
            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, null);

            PageData pageData = new PageData();
            pageData.PageSize = pageSize;
            pageData.CurPage = curPage;
            pageData.RecordCount = 0;
            pageData.PageCount = 1;

            int first = (curPage - 1) * pageSize + 1;
            int last = curPage * pageSize;

            while (oleDbDataReader.Read())
            {
                pageData.RecordCount++;
                if (pageData.RecordCount >= first && last >= pageData.RecordCount)
                {
                    Wuyefei wuyefei = new Wuyefei();
                    ReadWuyefeiPageData(oleDbDataReader, wuyefei);
                    list.Add(wuyefei);
                }
            }
            oleDbDataReader.Close();

            if(pageData.RecordCount>0)
                pageData.PageCount = Convert.ToInt32(Math.Ceiling((double)pageData.RecordCount / (double)pageSize));

            pageData.PageList = list;
            return pageData;
        }

        #endregion EasyCode所生成的默认代码

        //﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉
        //  说明：以下区域的代码为设计开发人员所编写，主要为扩展该数据访问类的功能，而定义的变量、属性及相关数据访问方法。  
        //  注意：为了保证该项目的多数据库支持与扩展性，请先在本类的父类中对相关抽象方法进行定义，再在本类中进行具体实现。
        //﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍



        public override List<Wuyefei> GetDataByFangyuanIndex( int index )
        {
            string sqlText = "SELECT * "
                           + "FROM [wuyefei]"
                           + "WHERE [fangyuanindex]=@index";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@index" , OleDbType.Integer , 4){ Value = index }
            };

            List<Wuyefei> list = new List<Wuyefei>();
            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, parameters);
            while (oleDbDataReader.Read())
            {
                Wuyefei wuyefei = new Wuyefei();
                ReadWuyefeiAllData(oleDbDataReader, wuyefei);
                list.Add(wuyefei);
            }
            oleDbDataReader.Close();
            return list;
        }







    }
}
